package eu.telecom_bretagne.RECRUT.data.dao;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import eu.telecom_bretagne.RECRUT.data.model.Entretien;

/**
 * Session Bean implementation class EntretienDAO
 */
@Stateless
@LocalBean
public class EntretienDAO implements DAO<Entretien> {

	@PersistenceContext
	EntityManager entityManager;
	
    /**
     * Default constructor. 
     */
    public EntretienDAO() { }

	@Override
	public Entretien create(Entretien entity) {
		
		entityManager.persist(entity);
		return entity;
	}

	@Override
	public Entretien findById(int id) {
		
		return entityManager.find(Entretien.class,id);
	}

	@Override
	public Entretien update(Entretien entity) {
		
		return entity; // no-op.
	}

	@Override
	public void delete(Entretien entity) {
		
		entityManager.remove(entity);
	}

	@SuppressWarnings("unchecked")
	public List<Entretien> findAll() {
		Query query = entityManager
				.createQuery("select entretien from Entretien entretien");
		return (List<Entretien>) query.getResultList();
	}

}
